#define QT_NO_KEYWORDS // 关键：避免Qt关键字与GLib冲突
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
#include <iostream>
#include <libnotify/notify.h> // libnotify库头文件

int main(int argc, char *argv[]) {
  QApplication app(argc, argv);

  // 初始化libnotify
  if (!notify_init("Qt Notification Example")) {
    std::cerr << "Failed to initialize libnotify!" << std::endl;
    return 1;
  }

  QWidget mainWindow;
  mainWindow.setWindowTitle("Qt + libnotify 示例");
  mainWindow.resize(400, 300);

  QVBoxLayout *layout = new QVBoxLayout(&mainWindow);

  QPushButton *button = new QPushButton("点击发送通知（libnotify）");
  button->setFixedSize(200, 40);
  layout->addWidget(button, 0, Qt::AlignCenter);

  // 关联按钮点击事件
  QObject::connect(button, &QPushButton::clicked, []() {
    NotifyNotification *n = notify_notification_new(
        "通知标题", "这是通过libnotify发送的通知！", "dialog-information");

    notify_notification_set_timeout(n, 5000);

    GError *error = nullptr;
    if (!notify_notification_show(n, &error)) {
      std::cerr << "Failed to show notification: " << error->message
                << std::endl;
      g_error_free(error);
    }

    g_object_unref(G_OBJECT(n));
  });

  mainWindow.show();
  int ret = app.exec();
  notify_uninit();
  return ret;
}